{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "42dd2777",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "THU 14:04\n"
     ]
    }
   ],
   "source": [
    "# 解码约会时间 - 将题目的 4 行输入解码为 'DAY HH:MM'\n",
    "DAY_MAP = {\n",
    "    'A': 'MON', 'B': 'TUE', 'C': 'WED', 'D': 'THU', 'E': 'FRI', 'F': 'SAT', 'G': 'SUN'\n",
    "}\n",
    "\n",
    "def decode_time(s1: str, s2: str, s3: str, s4: str) -> str:\n",
    "    n12 = min(len(s1), len(s2))\n",
    "    day_char = None\n",
    "    i = 0\n",
    "    while i < n12:\n",
    "        if s1[i] == s2[i] and 'A' <= s1[i] <= 'G':\n",
    "            day_char = s1[i]\n",
    "            break\n",
    "        i += 1\n",
    "    if day_char is None:\n",
    "        raise ValueError('No valid day character found')\n",
    "\n",
    "    hour_char = None\n",
    "    j = i + 1\n",
    "    while j < n12:\n",
    "        if s1[j] == s2[j]:\n",
    "            ch = s1[j]\n",
    "            if '0' <= ch <= '9' or 'A' <= ch <= 'N':\n",
    "                hour_char = ch\n",
    "                break\n",
    "        j += 1\n",
    "    if hour_char is None:\n",
    "        raise ValueError('No valid hour character found')\n",
    "\n",
    "    if '0' <= hour_char <= '9':\n",
    "        hour = int(hour_char)\n",
    "    else:\n",
    "        hour = ord(hour_char) - ord('A') + 10\n",
    "\n",
    "    n34 = min(len(s3), len(s4))\n",
    "    minute = None\n",
    "    k = 0\n",
    "    while k < n34:\n",
    "        if s3[k] == s4[k] and s3[k].isalpha():\n",
    "            minute = k\n",
    "            break\n",
    "        k += 1\n",
    "    if minute is None:\n",
    "        raise ValueError('No valid minute position found')\n",
    "\n",
    "    day = DAY_MAP[day_char]\n",
    "    return f\"{day} {hour:02d}:{minute:02d}\"\n",
    "\n",
    "def main():\n",
    "    data = []\n",
    "    for _ in range(4):\n",
    "        try:\n",
    "            line = input()\n",
    "        except EOFError:\n",
    "            break\n",
    "        data.append(line)\n",
    "    if len(data) < 4:\n",
    "        print('')\n",
    "        return\n",
    "    print(decode_time(data[0], data[1], data[2], data[3]))\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    main()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py39",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.23"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
